<?php
/*========================================= JooSam =========================================/
/																							/
/	Extention:		JooSam																	/
/	Created by:		ScriptPlanet.eu															/
/	Site:			http://www.scriptplanet.eu												/
/	Email:			support@scriptplanet.eu													/
/	Support:		http://www.scriptplanet.eu/support										/
/	Copyright:		2011 (c) ScriptPlanet.eu												/
/	License:		CC BY-NC-ND 3.0 ~ http://creativecommons.org/licenses/by-nc-nd/3.0/		/
/	File Version:	0001																	/
/																							/
/========================================== JooSam ========================================*/

// Joomla security
defined('_JEXEC') or die;


## JooSam Encrypt Function
class JoosamHelperJscrypt{

	## Keygen to create key (only on mcrypt)
	public function jskeygen(){

		$jconf =& JFactory::getApplication();
		$joomla_key = $jconf->getCfg('secret');
		$joosam_key = 'c3VwcG9ydEBzY3JpcHRwbGFuZXQuZXU=';
		$prekey = $joomla_key.$joosam_key;
		$key = base64_encode($prekey);
		return $key;
	}

	## Encode the key (only mcrypt)
	public function jsencrypt($password){

		$key = $this->jskeygen();
		$crypt = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $password, MCRYPT_MODE_CBC, md5(md5($key))));
		return $crypt;
	}

	## Decode the key (only mcrypt)
	public function jsdecrypt($password){

		$key = $this->jskeygen();
		$crypt = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($password), MCRYPT_MODE_CBC, md5(md5($key))));
		return $crypt;
	}

	## Encode the key (no mcrypt)
	public function jsbaseEncrypt($password){
		
		$crypt = base64_encode($password);
		return $crypt;
	}

	## Decode the key (no mcrypt)
	public function jsbaseDecrypt($password){
		
		$crypt = base64_decode($password);
		return $crypt;
	}

}